<?php
namespace app\common\command;

use think\Exception;

use app\admin\model\Member as MemberMdl;

class Member
{
    /**
     * 会员生日自动增加积分
     */
    public static function integral()
    {
        try {
            $where = [
                'birthday' => ['like', '%'.date('m-d') .'%']
            ];
            $fields = 'a.id,m.birthday_quantity,is_birthday_integral';
            $result = MemberMdl::alias('a')
                ->where($where)
                ->join('member_level m','a.member_level_id = m.id')
                ->field($fields)
                ->select();
            if (!$result){
                return;
            }
            foreach ($result as $v)
            {
                if ($v['is_birthday_integral'] == 1){
                    MemberMdl::where('id',$v['id'])->setInc('integral',$v['birthday_quantity']);
                }
            }
        } catch (Exception $e) {
            trace($e->getMessage(), 'error');
        }
    }
}